package orz.itrip.biz.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import orz.itrip.DtoUtils;
import orz.itrip.biz.service.HotelOrderService;
import orz.itrip.biz.vo.GetOrderListVo;
import orz.itrip.vo.GetPreOrderVo;
import orz.itrip.dto.Dto;
import orz.itrip.vo.HotelOrderAddVo;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;

@RestController
@RequestMapping("/api/hotelorder")
@Api(tags = "酒店订单",description = "文档说明",hidden = true)
public class HotelOrderController {

    @Resource
    private HotelOrderService hotelOrderService;

    @PostMapping(value = "getpersonalorderlist",headers = "token")
    @ApiOperation( value = "查看个人中心",notes = "在个人中心显示用户订单")
    public Dto getpersonalorderlist(@RequestBody GetOrderListVo getOrderListVo,HttpServletRequest request) throws ParseException {
        String token = request.getHeader("token");
        if (!StringUtils.isEmpty(token)) {
            return hotelOrderService.getpersonalorderlist(getOrderListVo,token);
        }
        return DtoUtils.getFalseDto("token失效，请重登录","100000");
    }

    @GetMapping(value = "getpersonalorderinfo/{orderId}",headers = "token")
    @ApiOperation(value = "订单详情",notes = "查询单个订单详情")
    public Dto getpersonalorderinfo(@PathVariable(value = "orderId") Long orderId, HttpServletRequest request){
        String token = request.getHeader("token");
        if (!StringUtils.isEmpty(token)) {
            return hotelOrderService.getpersonalorderinfo(orderId,token);
        }
        return DtoUtils.getFalseDto("token失效，请重登录","100000");
    }
    @GetMapping(value = "getpersonalorderroominfo/{orderId}",headers = "token")
    @ApiOperation(value = "订单房间详情",notes = "查询单个订单房间详情")
    public Dto getpersonalorderroominfo(@PathVariable(value = "orderId") Long orderId,HttpServletRequest request){
        String token = request.getHeader("token");
        if (!StringUtils.isEmpty(token)) {
            return hotelOrderService.getpersonalorderroominfo(orderId,token);
        }
        return DtoUtils.getFalseDto("token失效，请重登录","100000");
    }

    @PostMapping(value = "getpreorderinfo",headers = "token")
    @ApiOperation( value = "获取个人订单",notes = "获取个人订单")
    public Dto getpreorderinfo(@RequestBody GetPreOrderVo getPreOrderVo, HttpServletRequest request){
        String token = request.getHeader("token");
        if (!StringUtils.isEmpty(token)) {
            return hotelOrderService.getpreorderinfo(getPreOrderVo);
        }
        return DtoUtils.getFalseDto("token失效，请重登录","100000");
    }

    @PostMapping(value = "addhotelorder",headers = "token")
    @ApiOperation( value = "获取个人订单",notes = "获取个人订单")
    public Dto addhotelorder(@RequestBody HotelOrderAddVo hotelOrderAddVo, HttpServletRequest request){
        String token = request.getHeader("token");
        if (!StringUtils.isEmpty(token)) {
            return hotelOrderService.addhotelorder(hotelOrderAddVo,token);
        }
        return DtoUtils.getFalseDto("token失效，请重登录","100000");
    }

    @GetMapping(value = "queryOrderById/{orderId}",headers = "token")
    @ApiOperation(value = "订单房间详情",notes = "查询单个订单房间详情")
    public Dto queryOrderById(@PathVariable(value = "orderId") Long orderId,HttpServletRequest request){
        String token = request.getHeader("token");
        if (!StringUtils.isEmpty(token)) {
            return hotelOrderService.queryOrderById(orderId);
        }
        return DtoUtils.getFalseDto("token失效，请重登录","100000");
    }
}
